package com.cloud.exception;

import com.cloud.constant.SystemConstant;
import com.cloud.utils.Result;
import com.cloud.utils.ResultUtils;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2017/11/13 0013.
 */
@ControllerAdvice
public class GlobleException {
    Logger logger = LoggerFactory.getLogger(GlobleException.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handleException(Exception e) {
        if (e instanceof AuthorizationException) {
            return ResultUtils.unauthorized("您没有相应权限");
        }else {
            logger.error("未知错误={}", e.getMessage());
            return ResultUtils.error(SystemConstant.UNKNOW_ERROR, "未知错误");
        }
    }
}
